import svg
import math
import random


bible_books = dict()

        
chaptercount = 0
with open('biblebooks2.txt') as b:
    for l in b:

        li = l.strip(' ').strip('\n')
        if not li == '':
            li = li.split('.')
            bible_books[li[0].strip(' ')]=chaptercount
            chaptercount += int(li[1])
 


arch_svg = svg.svg()

colors = 'yellow,green,purple,blue,orange,red'.split(',')
scale =.6
shiftdown=450
shiftright=10
def draw_half_circle(arch_svg,id,x,y,r,color,oncl="",onmouseov="",onmouseou=""):
    x1 = x-r
    y1 = y
    x2 = x+r
    y2 = y
    arch_svg.add(svg.circle_wedge(x1, y1, x2, y2, r, r,\
                       x_rotate=0,large_arch=0,sweep_flag=1, 
                       style={'stroke':color,'stroke-width':1,'fill':'none'},\
                       fields={'id':id, 'onclick':oncl,'onmouseover':onmouseov,'onmouseout':onmouseou}))

skip = 30
prophlist=[]


with open("prophecy.txt") as proph:
    i = 0
    j = 0
    for l in proph:    
        line = l.split('=')
        truecolors = []
        firstverses = []
        lastverses = []
        for ref1  in line[1].split(';'):
            ref1name = ref1.strip(' ').split('.')
            ref1booknum = int(bible_books[ref1name[0]]) + int(ref1name[1].split(':')[0])
            firstverses.append(ref1.strip(' '))
            lastverses = []
            for ref2 in line[2].split(';'):
                ref2name = ref2.strip(' ').split('.')

                ref2booknum = int(bible_books[ref2name[0]]) + int(ref2name[1].split(':')[0])
#                color = colors[int((ref2booknum-ref1booknum)*len(colors)/chaptercount*2 % len(colors) )]
                lastverses.append(ref2.strip(' '))
                x = (ref1booknum+(ref2booknum-ref1booknum)/2)*scale+shiftright
                y=shiftdown
                r=(ref2booknum-ref1booknum)*scale/2
                color = colors[int((r)*len(colors)/chaptercount*5 % len(colors))]
                prophlist.append((i,x,y,r,color))
                truecolors.append('%s.%s' % (i,color))
                i+=1

        l = l.strip('\n')
        part = l.split('=')
        firstverses = ';'.join(firstverses)
        
        lastverses= ';'.join(lastverses)
        
        lastverses = lastverses.replace('.',' ').replace(';','   ').strip('\n')
        firstverses = firstverses.replace('.',' ').replace(';','   ').strip('\n')

        tclist = ';'.join(truecolors).strip('\n')
        
        
        # mouseClickProph(id,sourceverses,destverses,tclist)
        
#        square = svg.square(1+chaptercount*scale+shiftright+22*int(j/10),10+22*(j%10) , 12,style={'fill':'white'})
        
        line = svg.text(1+chaptercount*scale+shiftright,15+15*j,\
                         part[0],\
                         style={'fill':'white','font-size':'11px'},\
                         fields={'id':('text:%s'%j),\
                                 'onclick':"mouseClickProph('%s','%s','%s')"%(firstverses,lastverses,tclist),\
                                 'onmouseover':("allColor('%s','white')" % tclist),\
                                 'onmouseout':"restoreColor('%s')" % tclist}\
                        )

        j+=1 
        arch_svg.add(line)


#856 429 1214
for p in prophlist:
    color = p[4]
    draw_half_circle(arch_svg,p[0],p[1],p[2],p[3],color)#,onmouseov="colorChange('%arch_svg','%arch_svg')"%(p[0],'white'),onmouseou="colorChange('%arch_svg','%arch_svg')"%(p[0],color))

arch_svg.add(svg.line(shiftright,shiftdown+1,chaptercount*scale,shiftdown+1,\
                      style={'stroke':'lightgrey','stroke-width':2}))


reference = svg.text(1+shiftright,shiftdown+80,'Prophicy list derived from clarifyingchristianity.com',\
                     style={'fill':'grey','font-size':'10px'})
reference = svg.linkify(reference,'http://www.clarifyingchristianity.com/m_prophecies.shtml')
arch_svg.add(reference)

arch_svg.add( svg.text(25,25,'Old Testament prophecies that Jesus Christ fufilled',\
                       style={'fill':'grey','font-size':'20px'}))

arch_svg.add( svg.text(30,45,'Arches connect prophecy and fufillment verses. Click on a prophecy to view verse linkages.'\
                       ,style={'fill':'white','font-size':'13px'}))

arch_svg.add( svg.text(shiftright,shiftdown+15,
                ' ',style={'fill':'white','font-size':12}))
arch_svg.add( svg.text(chaptercount*scale,shiftdown+15,\
                ' ',style={'fill':'white','font-size':12}, text_anchor='end'))

with open('out/prophecy.svg','w') as f:
            f.write( (arch_svg.get_svg()))
